package org.csu.equipment.controller;

import org.csu.equipment.entity.Client;
import org.csu.equipment.entity.ClientLogin;
import org.csu.equipment.entity.Task;
import org.csu.equipment.service.ClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class ClientController {

    @Autowired
    ClientService clientService;


    @GetMapping("/updateinfo")
    public  String updateInfo(Client client,String CPwd,Model model){
        ClientLogin clientLogin=new ClientLogin();
        clientService.updateInfo(client);
        clientLogin.setCId(client.getCId());
        clientLogin.setCPwd(CPwd);
        clientService.updatePwd(clientLogin);
        List<Task> taskList= clientService.getTask(client.getCId());
        model.addAttribute("tasklist",taskList);
        model.addAttribute("client",client);
        return "client/clients";

    }

    @GetMapping("/clientlogin")
   public  String clientlogin(String CId, String CPwd, Model model){
         Integer c=clientService.login(CId,CPwd);

         if(c==1){
             List<Task> taskList= clientService.getTask(CId);
             model.addAttribute("tasklist",taskList);
             model.addAttribute("client",clientService.getClient(CId));
             return "client/clients";
         }

        model.addAttribute("msg","账户密码不正确");
        return "/index";
   }

    @RequestMapping(value = "/newtask",method = RequestMethod.POST)
    @ResponseBody
    public  String newtask(String CId,String CAddress,String CEmail,String CPhone,String skill,String description)  {
        Client client=  new Client();
        client.setCId(CId);
        client.setCAddress(CAddress);
        client.setCEmail(CEmail);
        client.setCPhone(CPhone);
        System.out.println(client);
        clientService.newTask(client,description,skill);
        return "SUCCESS";
    }

    @RequestMapping(value = "/tixing",method = RequestMethod.POST)
    @ResponseBody
    public  String tixing(String TId){
        if(clientService.isNotG(TId))
        clientService.reminder(TId);
        return "SUCCESS";
    }

    @RequestMapping(value = "/commentE",method = RequestMethod.GET)//评价一下吧，爹！
    @ResponseBody
    public String commentE(String EId , String credit,String TId){
        System.out.println(TId);
        clientService.CommentEmploy(EId,Integer.parseInt(credit),TId);
        return "SUCCESS";
    }





}
